#include "stdafx.h"
#include "PaintExample.h"

void PaintExample::loadFile(const String& fileName, FCView *view){
    FCUIXml::loadFile(fileName, view);
    FCTabPage *tabPage1 = getTabPage(L"TabPage");
    FCTabPage *tabPage2 = getTabPage(L"TabPage2");
    FCTabPage *tabPage3 = getTabPage(L"TabPage3");
    FCTabPage *tabPage4 = getTabPage(L"TabPage4");
    FCTabPage *tabPage5 = getTabPage(L"TabPage5");
    FCTabPage *tabPage6 = getTabPage(L"TabPage6");
    tabPage1->addEvent((FCPaintEventCallBack*)this, FCEventID_Paint, this);
    tabPage2->addEvent((FCPaintEventCallBack*)this, FCEventID_Paint, this);
    tabPage3->addEvent((FCPaintEventCallBack*)this, FCEventID_Paint, this);
    tabPage4->addEvent((FCPaintEventCallBack*)this, FCEventID_Paint, this);
    tabPage5->addEvent((FCPaintEventCallBack*)this, FCEventID_Paint, this);
    tabPage6->addEvent((FCPaintEventCallBack*)this, FCEventID_Paint, this);
}

bool PaintExample::callPaintEvent(String eventName, Object sender, FCPaint *paint, const FCRect& clipRect, Object invoke){
    FCView *view = (FCView*)sender;
    String name = view->getName();
    if (name == L"TabPage")
    {
        paint->drawLine(FCColor::rgb(255, 0, 0), 1, 0, 100, 100, 300, 300);
        paint->drawLine(FCColor::rgb(255, 0, 255), 5, 2, 100, 300, 300, 100);
    }
    else if (name == L"TabPage2")
    {
        paint->drawRect(FCColor::rgb(0, 255, 0), 1, 0, 100, 100, 200, 200);
        paint->fillRect(FCColor::rgb(0, 0, 255), 250, 250, 350, 350);
    }
    else if (name == L"TabPage3")
    {
        paint->drawEllipse(FCColor::rgb(0, 255, 255), 1, 0, 100, 100, 200, 200);
        FCRect eRect = {250, 250, 350, 350};
        paint->fillEllipse(FCColor::rgb(255, 0, 255), eRect);
    }
    else if (name == L"TabPage4")
    {
        String text = L"FaceCat";
        FCFont tFont(L"Default", 30);
        FCSize tSize = paint->textSize(text, &tFont);
        FCRect tRect = {100, 100, 100 + tSize.cx, 100 + tSize.cy};
        paint->drawText(text, FCColor::rgb(255, 0, 0), &tFont, tRect);
    }
    else if (name == L"TabPage5")
    {
        FCPoint points[5] = {0};
        points[0].x = 100;
        points[0].y = 100;
        points[1].x = 150;
        points[1].y = 120;
        points[2].x = 130;
        points[2].y = 200;
        points[3].x = 200;
        points[3].y = 200;
        points[4].x = 250;
        points[4].y = 220;
        paint->drawPolyline(FCColor::rgb(255, 0, 0), 1, 0, points, 5);
    }
    else if (name == L"TabPage6")
    {
        FCPoint points[4] = {0};
        points[0].x = 100;
        points[0].y = 100;
        points[1].x = 150;
        points[1].y = 120;
        points[2].x = 200;
        points[2].y = 200;
        points[3].x = 150;
        points[3].y = 200;
        paint->fillPolygon(FCColor::rgb(0, 0, 255), points, 4);
    }
    return false;
}
